#include "quat.h"
#include "vect.h"
#include "mat4.h"

const quat quat::ZERO = quat(0, 0, 0, 0);
const quat quat::IDENTITY = quat(1, 0, 0, 0);

vect quat::rotate(const vect& v) const {
	return toMatrix() * v;
}

mat4 quat::toMatrix() const {
	return mat4(
		w*w+x*x-y*y-z*z, 2*x*y+2*w*z, 2*x*z-2*w*y, 0,
		2*x*y-2*w*z, w*w-x*x+y*y-z*z, 2*y*z+2*w*x, 0,
		2*x*z+2*w*y, 2*y*z-2*w*x, w*w-x*x-y*y+z*z, 0,
		0,	0,	0,	1
	);
}
